package com.isorf.test;

import com.isorf.pojo.shoe;
import com.isorf.pojo.inventory;
import com.isorf.pojo.brand;
import com.isorf.pojo.type;
import com.isorf.pojo.color;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * Simple inventory functionality test class
 */
public class InventoryTestEnglish {

    /**
     * Test creating shoe object and inventory objects
     */
    public static void main(String[] args) {
        System.out.println("=== Starting Inventory Function Test ===");
        
        try {
            // 1. Create shoe object
            shoe shoe = new shoe();
            
            // Set basic shoe information
            shoe.setShoeName("Test Sports Shoe");
            shoe.setSerialNumber("TEST001");
            shoe.setPrice(new BigDecimal("299.99"));
            shoe.setDiscountedPrice(new BigDecimal("249.99"));
            shoe.setReleaseDate(new Date());
            shoe.setOrigin("China");
            shoe.setGender("Male");
            shoe.setDescription("This is a test sports shoe");
            shoe.setTotalSales(0);
            shoe.setDetailInfo("Detailed shoe information");
            shoe.setPoints(100);
            shoe.setShoeStatus(1);
            shoe.setImageUrl("/upload/test-shoe.jpg");
            
            // 2. Set brand information
            brand brand = new brand();
            brand.setBrandid(1);
            brand.setBrandgender("Male");
            brand.setBrandstatus(1);
            brand.setBrandremarks("Test Brand");
            shoe.setBrand(brand);
            
            // 3. Set type information
            type shoeType = new type();
            shoeType.setTypeid(1);
            shoeType.setShoestype("Sports Shoe");
            shoeType.setTypestatus("1"); // Fix: use String type
            shoeType.setTypemarks("Test Type");
            shoe.setShoeType(shoeType);
            
            // 4. Set color information
            color color = new color();
            color.setColorId(1);
            color.setColorName("Black");
            color.setColorStatus(1);
            color.setColorMarks("Test Color");
            shoe.setColor(color);
            
            // 5. Create inventory list
            List<inventory> inventoryList = new ArrayList<>();
            
            // Add different size inventories
            inventory inv1 = new inventory();
            inv1.setSizeId(1);
            inv1.setQuantity(10);
            inventoryList.add(inv1);
            
            inventory inv2 = new inventory();
            inv2.setSizeId(2);
            inv2.setQuantity(15);
            inventoryList.add(inv2);
            
            inventory inv3 = new inventory();
            inv3.setSizeId(3);
            inv3.setQuantity(8);
            inventoryList.add(inv3);
            
            // Set inventory list to shoe object
            shoe.setInventoryList(inventoryList);
            
            System.out.println("SUCCESS: Shoe object created successfully!");
            System.out.println("Shoe Name: " + shoe.getShoeName());
            System.out.println("Shoe Price: " + shoe.getPrice());
            System.out.println("Brand ID: " + shoe.getBrand().getBrandid());
            System.out.println("Type ID: " + shoe.getShoeType().getTypeid());
            System.out.println("Color ID: " + shoe.getColor().getColorId());
            System.out.println("Inventory Count: " + inventoryList.size() + " sizes");
            
            // Print inventory details
            System.out.println("\nInventory Details:");
            for (int i = 0; i < inventoryList.size(); i++) {
                inventory inv = inventoryList.get(i);
                System.out.println("  Inventory" + (i+1) + ": SizeID=" + inv.getSizeId() + ", Quantity=" + inv.getQuantity());
            }
            
            // 6. Test data validation
            testDataValidation(shoe, inventoryList);
            
        } catch (Exception e) {
            System.out.println("ERROR: Exception occurred during test: " + e.getMessage());
            e.printStackTrace();
        }
        
        System.out.println("=== Test Completed ===");
    }
    
    /**
     * Test data validation
     */
    private static void testDataValidation(shoe shoe, List<inventory> inventoryList) {
        System.out.println("\n=== Data Validation Test ===");
        
        // Validate basic shoe information
        if (shoe.getShoeName() != null && !shoe.getShoeName().isEmpty()) {
            System.out.println("SUCCESS: Shoe name validation passed");
        } else {
            System.out.println("ERROR: Shoe name validation failed");
        }
        
        if (shoe.getPrice() != null && shoe.getPrice().compareTo(BigDecimal.ZERO) > 0) {
            System.out.println("SUCCESS: Shoe price validation passed");
        } else {
            System.out.println("ERROR: Shoe price validation failed");
        }
        
        // Validate brand information
        if (shoe.getBrand() != null && shoe.getBrand().getBrandid() != null) {
            System.out.println("SUCCESS: Brand information validation passed");
        } else {
            System.out.println("ERROR: Brand information validation failed");
        }
        
        // Validate type information
        if (shoe.getShoeType() != null && shoe.getShoeType().getTypeid() != null) {
            System.out.println("SUCCESS: Type information validation passed");
        } else {
            System.out.println("ERROR: Type information validation failed");
        }
        
        // Validate color information
        if (shoe.getColor() != null && shoe.getColor().getColorId() != null) {
            System.out.println("SUCCESS: Color information validation passed");
        } else {
            System.out.println("ERROR: Color information validation failed");
        }
        
        // Validate inventory information
        if (inventoryList != null && !inventoryList.isEmpty()) {
            System.out.println("SUCCESS: Inventory list validation passed");
            
            // Validate each inventory item
            for (int i = 0; i < inventoryList.size(); i++) {
                inventory inv = inventoryList.get(i);
                if (inv.getSizeId() != null && inv.getQuantity() != null && inv.getQuantity() > 0) {
                    System.out.println("SUCCESS: Inventory" + (i+1) + " validation passed");
                } else {
                    System.out.println("ERROR: Inventory" + (i+1) + " validation failed");
                }
            }
        } else {
            System.out.println("ERROR: Inventory list validation failed");
        }
        
        System.out.println("=== Data Validation Completed ===");
    }
    
    /**
     * Test empty inventory scenario
     */
    public static void testEmptyInventory() {
        System.out.println("\n=== Test Empty Inventory Scenario ===");
        
        shoe shoe = new shoe();
        shoe.setShoeName("Empty Inventory Test Shoe");
        shoe.setPrice(new BigDecimal("199.99"));
        
        // Set empty inventory list
        shoe.setInventoryList(new ArrayList<>());
        
        if (shoe.getInventoryList() != null && shoe.getInventoryList().isEmpty()) {
            System.out.println("SUCCESS: Empty inventory list created successfully");
        } else {
            System.out.println("ERROR: Empty inventory list creation failed");
        }
    }
    
    /**
     * Test null inventory scenario
     */
    public static void testNullInventory() {
        System.out.println("\n=== Test Null Inventory Scenario ===");
        
        shoe shoe = new shoe();
        shoe.setShoeName("Null Inventory Test Shoe");
        shoe.setPrice(new BigDecimal("159.99"));
        
        // Set null inventory list
        shoe.setInventoryList(null);
        
        if (shoe.getInventoryList() == null) {
            System.out.println("SUCCESS: Null inventory list set successfully");
        } else {
            System.out.println("ERROR: Null inventory list setting failed");
        }
    }
} 